import React from 'react';
import ImagePicker from 'react-native-image-crop-picker';
import {ActionSheet} from 'teaset';
const ImageUtils = {
    selectAvatar(opts,completion, error) {
        const options = {
            compressImageMaxWidth: 500,
            compressImageMaxHeight: 500,
            compressImageQuality: 0.7,
            compressVideoPreset: 'MediumQuality',
            cropping: true,
            cropperCircleOverlay: true,
            useFrontCamera: true,
            cropperCancelText: '取消',
            cropperChooseText: '确定',
            mediaType: 'photo',
            ...opts
        };
        let items = [
            {
                title: '拍照', onPress: () => ImagePicker.openCamera(options).then(image => {
                    completion && completion(image.path);
                }).catch(error),
            },
            {
                title: '从相册选择', onPress: () => ImagePicker.openPicker(options).then(image => {
                    completion && completion(image.path);
                }).catch(error)
            },
        ];
        let cancelItem = {title: '取消'};
        ActionSheet.show(items, cancelItem);
    },
    selectImage(opts, completion, error) {
        const options = {
            compressImageMaxWidth: 500,
            compressImageMaxHeight: 500,
            compressImageQuality: 0.7,
            compressVideoPreset: 'MediumQuality',
            cropping: false,
            mediaType: 'photo',
            ...opts
        };
        let items = [
            {
                title: '拍照', onPress: () => ImagePicker.openCamera(options).then(image => {
                    completion && completion(image.path);
                }).catch(error),
            },
            {
                title: '从相册选择', onPress: () => ImagePicker.openPicker(options).then(image => {
                    completion && completion(image.path);
                }).catch(error)
            },
        ];
        let cancelItem = {title: '取消'};
        ActionSheet.show(items, cancelItem);
    }
};

export default ImageUtils;
